package edu.hunau.cxb19.oop.class17;

import org.junit.Test;

import edu.hunau.cxb19.oop.class17.generic.Counter;
import edu.hunau.cxb19.oop.class17.generic.Food;
import edu.hunau.cxb19.oop.class17.generic.Pet;
import edu.hunau.cxb19.oop.class17.generic.Shop;

/**
 *
 * @author hb
 *
 *         2020-03-18 15:06:44
 */
public class ShopTest {

	@Test
	public void test() {
		// 实例化一个食品店
		Shop<Food> foodShop = new Shop<Food>();
		System.out.println(foodShop.getClass());// class edu.hunau.cxb19.oop.class17.generic.Shop
		System.out.println(foodShop instanceof Shop);
		// System.out.println(foodShop instanceof Shop<Food>);编译失败
		// 食品店进货
		foodShop.addProduct(new Food("面包"));
		// 添加宠物
		// foodShop.addProduct(new Pet("吉娃娃"));//编译失败

		// 实例化一个宠物店
		Shop<Pet> petShop = new Shop<Pet>();
		petShop.addProduct(new Pet("哈士奇"));
		// petShop.addProduct(new Food("包子"));//编译失败

		// 从 jdk7.x 提供了菱形语法
		Shop<Pet> petShop2 = new Shop<>();

	}

	public void testCounter() {
		//在泛型约束中只能使用包装类
		Counter<Character, Integer> counter = new Counter<>();
		counter.setK('a');
		counter.setV(100);
	}
}
